#!/bin/bash

# 定义颜色
BLUE='\033[0;34m'
NC='\033[0m' # No Color

echo -e "${BLUE}--------------------------------------${NC}"
echo -e "${BLUE}系统基本信息：${NC}"
echo -e "${BLUE}--------------------------------------${NC}"
echo -e "Current Time: $(date '+%Y年 %m月 %d日 %A %T %Z')"
echo -e "Version      : $(cat /etc/redhat-release || cat /etc/issue)"
echo -e "Kernel       : $(uname -r)"
echo -e "Uptime       : $(uptime -p)"
echo -e "IP addr      : $(hostname -I | awk '{print $1}')"
echo -e "公网ip       : $(wget -4qO- http://whatismyip.akamai.com/)"
echo -e "Hostname     : $(hostname)"
echo -e "Cpu          : $(lscpu | grep 'Model name' | awk -F ': ' '{print $2}' | sed 's/^ *//g')"
echo -e "Memory       : $(free -h | grep Mem | awk '{print $3 "/" $2}')"
echo -e "SWAP         : $(free -h | grep Swap | awk '{print $3 "/" $2}')"
echo -e "Users Logged : $(who | wc -l)"
echo

echo -e "${BLUE}--------------------------------------${NC}"
echo -e "${BLUE}cpu的负载情况${NC}"
echo -e "${BLUE}--------------------------------------${NC}"
echo -e "CPU load in 1 min is: $(uptime | awk -F 'load average:' '{print $2}' | cut -d, -f1)"
echo -e "CPU load in 5 min is: $(uptime | awk -F 'load average:' '{print $2}' | cut -d, -f2)"
echo -e "CPU load in 10 min is: $(uptime | awk -F 'load average:' '{print $2}' | cut -d, -f3)"
echo -e "CPU 使用率 is: $(top -bn1 | grep load | awk '{printf "%.2f%%\t\t\n", $(NF-2)}')"
echo

echo -e "${BLUE}--------------------------------------${NC}"
echo -e "${BLUE}内存的使用情况${NC}"
echo -e "${BLUE}--------------------------------------${NC}"
echo -e "内存总容量: $(free -h | grep Mem | awk '{print $2}')"
echo -e "内存空闲容量: $(free -h | grep Mem | awk '{print $4}')"
echo -e "内存缓存: $(free -h | grep Mem | awk '{print $6}')"
echo -e "内存使用率: $(free -m | awk 'NR==2{printf "%.2f%%\t\t", $3*100/$2 }')"
echo

echo -e "${BLUE}--------------------------------------${NC}"
echo -e "${BLUE}各分区使用率${NC}"
echo -e "${BLUE}--------------------------------------${NC}"
df -h | grep -E '^/dev/' | awk '{print $1 " 总空间: " $(NF-4)  " 已用空间: " $(NF-3)  " 可使用空间: " $(NF-2) " 使用率: " $(NF-1)}'
echo

echo -e "${BLUE}--------------------------------------${NC}"
echo -e "${BLUE}显示登录来源信息 ${NC}"
echo -e "${BLUE}--------------------------------------${NC}"
w
echo

echo -e "${BLUE}--------------------------------------${NC}"
